package com.eightbears.beboy.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.util.CommonUtils;
import com.eightbears.beboy.entity.ReserveEntity;

import static com.eightbears.beboy.entity.ReserveEntity.STATUS_AGREE;
import static com.eightbears.beboy.entity.ReserveEntity.STATUS_REFUSE;

public class ReserveListAdapter extends BaseQuickAdapter<ReserveEntity.ReserveInfo, BaseViewHolder> {


    private ImageView iv_status;
    private LinearLayout ll_select;


    public ReserveListAdapter() {
        super(R.layout.item_reserve, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ReserveEntity.ReserveInfo reserveInfo) {

        iv_status = baseViewHolder.getView(R.id.iv_status);
        ll_select = baseViewHolder.getView(R.id.ll_select);

        baseViewHolder.setText(R.id.tv_nickname, reserveInfo.getUser().getNickname())
                .setText(R.id.tv_publish_date, CommonUtils.TimeStamp2Date(reserveInfo.getCreated_at(), "yyyy-MM-dd HH:mm"))
                .setText(R.id.tv_num, reserveInfo.getNum())
                .setText(R.id.tv_date, CommonUtils.TimeStamp2Date(reserveInfo.getTime(), "yyyy-MM-dd HH:mm"))
                .setText(R.id.tv_phone, reserveInfo.getMobile())
                .addOnClickListener(R.id.tv_cancel)
                .addOnClickListener(R.id.tv_ok)
                .addOnClickListener(R.id.tv_call);

        Glide.with(mContext).load(reserveInfo.getUser().getCover()).crossFade().error(R.mipmap.default_head).
                into((ImageView) baseViewHolder.getView(R.id.iv_user_head));


        replaceView();

        if (reserveInfo.getStatus().equals(STATUS_AGREE)) {
            showAgreeIcon();
        } else if (reserveInfo.getStatus().equals(STATUS_REFUSE)) {
            showCancelIcon();
        } else {
            ll_select.setVisibility(View.VISIBLE);
        }
    }

    private void showAgreeIcon() {
        iv_status.setVisibility(View.VISIBLE);
        iv_status.setImageResource(R.mipmap.icon_tongyi);
        ll_select.setVisibility(View.GONE);
    }

    private void showCancelIcon() {
        iv_status.setVisibility(View.VISIBLE);
        iv_status.setImageResource(R.mipmap.icon_jujue);
        ll_select.setVisibility(View.GONE);
    }

    private void replaceView() {
        iv_status.setVisibility(View.GONE);
        ll_select.setVisibility(View.GONE);
    }

    public void agreeOrCancel(int postion, boolean isAgree) {
        int postion1 = postion;
        boolean isAgree1 = isAgree;
        notifyDataSetChanged();
    }
}
